package com.qu.waibao.home.adpater;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.qu.waibao.R;
import com.qu.waibao.base.BaseRecyclerAdapter;
import com.qu.waibao.bean.HomeService;
import com.qu.waibao.bean.OtherService;
import com.qu.waibao.network.NetManager;
import com.qu.waibao.utils.ImageLoader;
import com.qu.waibao.widget.TweetPicturesLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by Administrator on 2018/8/1.
 */

public class HomeServiceAdapter extends BaseRecyclerAdapter<OtherService.ServiceBean> {
    public HomeServiceAdapter(Context context, int mode) {
        super(context, mode);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateDefaultViewHolder(ViewGroup parent, int type) {
        return new CallViewHodler(mInflater.inflate(R.layout.recycler_item_layout,parent,false));
    }

    @Override
    protected void onBindDefaultViewHolder(RecyclerView.ViewHolder holder, OtherService.ServiceBean item, int position) {
        CallViewHodler homeViewHolder = (CallViewHodler) holder;
        ImageLoader.loadImage(Glide.with(mContext),homeViewHolder.circleImageView, NetManager.getFullUrl(item.getPhoto()),
                R.drawable.sy_touxiang,R.drawable.sy_touxiang);
        if(TextUtils.isEmpty(item.getImgs())){
            homeViewHolder.ll_images.setVisibility(View.GONE);
        }else {
            String[] images = item.getImgs().split(",");
            homeViewHolder.mTweetPicturesLayout.setImage(images);
        }
        homeViewHolder.tv_nick.setText(item.getSecondname());
        homeViewHolder.tv_type.setText(item.getServicecategoryname());
        homeViewHolder.tv_status.setText(item.getState());
        if(item.getState().equals("待抢单")){
            homeViewHolder.tv_status.setTextColor(Color.parseColor("#3a9de2"));
        }else if(item.getState().equals("待完成")){
            homeViewHolder.tv_status.setTextColor(Color.parseColor("#cc3333"));
        }else if(item.getState().equals("待支付")){
            homeViewHolder.tv_status.setTextColor(Color.parseColor("#f29f1b"));
        }else if(item.getState().equals("已完成")){
            homeViewHolder.tv_status.setTextColor(Color.parseColor("#333333"));
        }else if(item.getState().equals("已取消")){
            homeViewHolder.tv_status.setTextColor(Color.parseColor("#333333"));
        }
        homeViewHolder.tv_content.setText(item.getRemark());
        if(item.getMoney_total().equals("0.00")){
            homeViewHolder.tv_money.setVisibility(View.GONE);
        }else {
            homeViewHolder.tv_money.setText("¥"+item.getMoney_total());
        }
        homeViewHolder.tv_time.setText(item.getCreatedate());
        homeViewHolder.tv_distance.setText(item.getDistance()+"km");
    }

    class CallViewHodler extends RecyclerView.ViewHolder{
        @BindView(R.id.mTweetPicturesLayout)
        TweetPicturesLayout mTweetPicturesLayout;
        @BindView(R.id.iv_photo)
        CircleImageView circleImageView;
        @BindView(R.id.tv_nick)
        TextView tv_nick;
        @BindView(R.id.tv_type)
        TextView tv_type;
        @BindView(R.id.tv_status)
        TextView tv_status;
        @BindView(R.id.tv_content)
        TextView tv_content;
        @BindView(R.id.tv_money)
        TextView tv_money;
        @BindView(R.id.tv_time)
        TextView tv_time;
        @BindView(R.id.tv_distance)
        TextView tv_distance;
        @BindView(R.id.ll_images)
        LinearLayout ll_images;
        public CallViewHodler(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }

}
